package com.thinkit.bigdata.web.controller;

import org.apache.log4j.Logger;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by joqk12345 on 9/2/16.
 * www.github.com/joqk12345
 */
@RestController
public class HelloWorldController  {
    public Logger logger = Logger.getLogger(HelloWorldController.class);

    @RequestMapping(value = "/hello",method = RequestMethod.GET)
    public ModelAndView helloworld(ModelAndView modelAndView){
//        modelAndView.addAttribute("index","this is thymeleaf test");
        modelAndView.addObject("index",new String("this is thymeleaf test"));
        logger.info("访问index 的返回值页面");

        modelAndView.setViewName("thymeleaf");
        return modelAndView;
    }

    @RequestMapping(value = "/es",method = RequestMethod.GET)
    public ModelAndView testEs(ModelAndView modelAndView){
//        modelAndView.addAttribute("index","this is thymeleaf test");
//        modelAndView.addObject("index",new String("this is thymeleaf test"));
//        logger.info("访问index 的返回值页面");

        modelAndView.setViewName("ElasticSearchView");
        return modelAndView;
    }

    //跳转至详情听音页面
    @RequestMapping(value = "/goDetail")
    public String goDetail(HttpServletRequest request, Model model) {
        String id = request.getParameter("id");
        String index = request.getParameter("index");//要查的第几条语音
        String length = request.getParameter("length");
        String strId = request.getParameter("strId");
        String type = request.getParameter("type");
        String task = request.getParameter("task");//语音编号列表

        model.addAttribute("id", id);
        model.addAttribute("length", length);//记录一共有几条语音
//        if (!StringUtil.isEmpty(index))
            model.addAttribute("index", index);
//        if (!StringUtil.isEmpty(strId))
            model.addAttribute("strId", strId);
//        if (!StringUtil.isEmpty(type))
            model.addAttribute("type", type);
//        if (!StringUtil.isEmpty(task)) {
            model.addAttribute("task", task);
//        } else {
//            model.addAttribute("task", "");
//        }
        return "detail";
    }
}
